package pers.qianyu.month_202012.date_20201219.bit_operation;

/**
 * 有用的位运算
 *
 * @author mizzle rain
 * @date 2020-12-19 20:35
 */
public class UsefulBitOperation {
    public static void main(String[] args) {
        // 字符转小写
        System.out.println((char) ('A' | ' '));
        System.out.println((char) ('a' | ' '));
        // 字符转大写
        System.out.println((char) ('b' & '_'));
        System.out.println((char) ('B' & '_'));
        // 字符大小写互转
        System.out.println((char) ('b' ^ ' '));
        System.out.println((char) ('B' ^ ' '));
        // 判断两个数知否异号
        System.out.println((-1 ^ 2) < 0);
        System.out.println((1 ^ 2) < 0);
        System.out.println((-1 ^ -2) < 0);
        // 交换两个数
        int a = 1, b = 2;
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        System.out.println("a = " + a);
        System.out.println("b = " + b);
    }
}
